#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9+7;
const int MAXN = 1000;
LL carge[MAXN], c_cnt;
LL dp[500][10007];

void solve() {
    int n = 10006;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i=1; i<=c_cnt; ++i) {
        int value = carge[i];
        for (int j=n; j>=0; --j) {
            dp[i][j] = dp[i-1][j];
            if (j-value>=0) dp[i][j] = (dp[i][j] + dp[i-1][j-value]) % MOD;
        }
    }
}

int main() {
#ifdef hai
    freopen("in.txt", "r", stdin);
#endif
    int T, ask;
    cin>>T;
    int v,c;
    while (T--) {
        int n,q;
        c_cnt = 1;
        scanf("%d %d", &n, &q);
        for (int i=0; i<n; ++i) {
            scanf("%d %d", &v, &c);
            for (int j=0; j<c; ++j) {
                carge[c_cnt++] = (1ll<<j)*v;
            }
        }
        --c_cnt;
//        for (int i=1; i<=c_cnt; ++i) printf("carge: %lld\n", carge[i]);
//        printf("\n");
        solve();
//        for (int i=0; i<=c_cnt; ++i) {
//            for (int j=0; j<20; ++j) printf("%lld ", dp[i][j]);
//            printf("\n");
//        }
        while (q--) {
            scanf("%d", &ask);
            printf("%lld\n", dp[c_cnt][ask]);
        }
    }
    return 0;
}
